<?php
class MainAction extends FrontAction {
    protected $subNav = FALSE;
    private $db = FALSE;
    protected function init() {
        if(!$this->checkConsoleLogin()) {
            $this->redirect('member/login');
            exit;
        }
        $act_name = strtolower(MODULE_NAME);
        $this->topNav[$act_name] = ' current';
        $act_name = strtolower(MODULE_NAME).'_'.strtolower(ACTION_NAME);
        $this->subNav[$act_name] = ' current';
        $this->assign('menu',W('consoleMenu',array(),true));
        $this->assign('currTopNav',$this->topNav);
        $this->assign('currSubNav',$this->subNav);
        $this->assign('user',$this->user);
        $this->assign('user_info',$this->user_info);

    }
    public function index() {
        $this->db = M('member');
        cookie('request_url',$this->getCurrentUrl());
        $where = ($_GET['rtype'] == 1 || $_GET['rtype'] == 2) ? 'a.`mid` = b.`mid` AND b.`recommend` = '.$_GET['rtype'] : 'a.`mid` = b.`mid`';
        $pre = C('db_prefix');
        $member = $this->getPageData($this->db,2,$where,'',array('`'.$pre.'member` a,'.'`'.$pre.'member_info` b'));
        $this->assign('member',$member);
        $this->display();
    }

    public function del() {

    }
    public function update() {

    }

    public function recommend() {
        $this->db = M('member_info');
        $pre = C('db_prefix');
        $re_member = $this->getPageData($this->db,30,'a.`mid` = b.`mid` AND a.`mid`=c.`mid`','b.`order` DESC',array('`'.$pre.'member_info` a,'.'`'.$pre.'member_recommend` b,'.'`'.$pre.'member` C'));
        $this->assign('member',$re_member);
        $this->display();
    }
    public function recommendAdd() {
        $mid = intval($_POST['mid']);
        $data['recommend'] = intval($_POST['rtype']);
        if(!$this->validTR(true)) {
            redirect(cookie('request_url'));
            exit();
        }
        if($mid ===0) {
            redirect(cookie('request_url'));
            exit();
        }
        M('member_info')->data($data)->where(array('mid'=>$mid))->save();
        redirect(cookie('request_url'));
    }
}